﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using GameEngine.SceneGraph;

namespace Redland2
{
    public class Level
    {
        #region members
        //private List<int> textTiles;
        //private List<Tile> tiles;
        public GameScene scene;
        public int _height = 19; // map height in blocks
        public int _width = 33; // map width in blocks
        char[,] map;
        #endregion members

        #region properties
        #endregion properties

        #region constructors

        public Level(string levelFileName, GameScene inputScene)
        {
            scene = inputScene;
            StreamReader MyStreamReader = new StreamReader(levelFileName);

            map = new char[_width, _height];
            char num;
            string line = "";

            //problem here
            // while ((num = MyStreamReader.Read()) != 5)
            //  line = MyStreamReader.ReadLine();
            for (int y = 0; y < _height; y++)
            {
                line = MyStreamReader.ReadLine();
                for (int x = 0; x < _width; x++)
                {
                    num = line[x];
                    map[x, y] = num;
                }
            }
            //    }//end while
            LoadMapTiles(map);
        }

        #endregion construcors

        #region methods
        void LoadMapTiles(char[,] map)
        {
            for (int y = 0; y < _height; y++)
            {
                for (int x = 0; x < _width; x++)
                {
                    switch (map[x,y])
                    {
                        
                        case '0':
                            //air
                            break;

                        case '1': //wall
                            scene._entities.Add(new Tile(scene, scene._entities.Count(), new Vector2((x * 40) - 20, (y * 40) - 20), 1));
                            break;

                        case '2': //lava
                            scene._entities.Add(new Tile(scene, scene._entities.Count(), new Vector2((x * 40) - 20, (y * 40) - 20), 2));                       
                            break;
                        case '3': //Pit
                            scene._entities.Add(new Tile(scene, scene._entities.Count(), new Vector2((x * 40) - 20, (y * 40) - 20), 3));                       
                            break;

                    }
                }
            }
        }

        #endregion method
    }
}
